package com.qls.mt.biz.demo;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.util.DigestUtils;


public class JLApiRequest {
    @JSONField(serialize = false)
    private String url;
    //客户编号
    private String appKey;
    //时间戳
    private long timestamp;
    //数字签名
    private String sign;
    //版本号
    private String version;
    @JSONField(serialize = false)
    //json类型的数据
    private JSONObject data;
//有参构造器，生成系统参数
    public JLApiRequest(String url, String appKey, String secretKey, Object data) {
        this.version = "3.0.0";
        this.timestamp = System.currentTimeMillis();
        this.appKey = appKey;
        this.data = (JSONObject) JSON.toJSON(data);
        this.sign = DigestUtils.md5DigestAsHex((DigestUtils.md5DigestAsHex((secretKey + appKey).getBytes()) + timestamp).getBytes());
        this.url = url;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    @Override
    public String toString() {
        return "JLApiRequest{" +
                "url='" + url + '\'' +
                ", appKey='" + appKey + '\'' +
                ", timestamp=" + timestamp +
                ", sign='" + sign + '\'' +
                ", version='" + version + '\'' +
                ", data=" + data +
                '}';
    }
}
